// SPDX-License-Identifier: GPL-2.0
#ifndef _NF_CONNTRACK_INNER_H
#define _NF_CONNTRACK_INNER_H

#include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_expect.h>

#ifdef CONFIG_ONT_NET_FEATURES

/* nf_conntrack_statis.c */
int nf_conn_statis_init(void);
void nf_conn_statis_fini(void);

void nf_conn_statis_try_insert_entry(const struct nf_conn *ct);
void nf_conn_statis_try_delete_entry(const struct nf_conn *ct);

/* nf_conntrack_expand.c */
void do_conntrack_del_hook(struct nf_conn *ct);
void nf_decrease_dev_ct_num(struct nf_conn *ct);
void nf_increase_dev_ct_num(struct nf_conn *ct);

bool nf_check_ct_reserved(struct nf_conn *ct);
bool nf_check_ct_eviction(int *cnt, bool *eviction);
bool nf_check_key_services(struct nf_conn *ct, struct nf_conn **select);
bool nf_force_ct_dropped(bool eviction, unsigned int drops, struct nf_conn *ct);

bool nf_nat_ports_used_up(void);
void nf_record_failed_alloc(void);
void nf_record_full_conntrack(void);

void nf_record_conntrack_before(struct sk_buff *skb, const struct nf_conn *ct);
void nf_record_conntrack_after(struct sk_buff *skb, const struct nf_conn *ct);

void nf_copy_master_template(struct nf_conn *ct);
void nf_setup_sip_expect(struct nf_conn *ct);

bool nf_check_tcp_flags(const struct sk_buff *skb, int dataoff, u8 pf, u8 protonum);
bool nf_check_udp_acct(const struct nf_conn *ct, u32 extra_jiffies, bool do_acct);

int do_conntrack_confirm_ipv4(struct sk_buff *skb, const struct nf_hook_state *state);
void nf_confirm_ipv4_hook(struct sk_buff *skb, const struct nf_hook_state *state, int ret);

/* nf_conntrack_expect_save.c */
int nf_ct_expect_save_init(void);
void nf_ct_expect_save_fini(void);

int exp_save_proc_init(struct net *net);
void exp_save_proc_remove(struct net *net);

void nf_ct_expect_save_insert(struct nf_conntrack_expect *exp);
void nf_ct_expect_save_remove(struct nf_conntrack_expect *exp);
void nf_ct_expect_save_replace(struct nf_conntrack_expect *exp, struct nf_conntrack_expect *rep);
void nf_ct_expect_nat_report(enum ip_conntrack_expect_events event,
			     struct nf_conntrack_expect *exp);

#else /* CONFIG_ONT_NET_FEATURES */

static inline int  nf_conn_statis_init(void) { return 0; }
static inline void nf_conn_statis_fini(void) { }

static inline void nf_conn_statis_try_insert_entry(const struct nf_conn *ct) { }
static inline void nf_conn_statis_try_delete_entry(const struct nf_conn *ct) { }

static inline void do_conntrack_del_hook(struct nf_conn *ct) { }
static inline void nf_decrease_dev_ct_num(struct nf_conn *ct) { }
static inline void nf_increase_dev_ct_num(struct nf_conn *ct) { }

static inline bool nf_check_ct_reserved(struct nf_conn *ct)
{
	return false;
}

static inline bool nf_check_ct_eviction(int *cnt, bool *eviction)
{
	return false;
}

static inline bool nf_check_key_services(struct nf_conn *ct, struct nf_conn **select)
{
	return false;
}

static inline bool nf_force_ct_dropped(bool eviction, unsigned int drops, struct nf_conn *ct)
{
	return false;
}

static inline bool nf_nat_ports_used_up(void)
{
	return false;
}

static inline void nf_record_failed_alloc(void) { }
static inline void nf_record_full_conntrack(void) { }

static inline void nf_record_conntrack_before(struct sk_buff *skb, const struct nf_conn *ct) { }
static inline void nf_record_conntrack_after(struct sk_buff *skb, const struct nf_conn *ct) { }

static inline void nf_copy_master_template(struct nf_conn *ct) { }
static inline void nf_setup_sip_expect(struct nf_conn *ct) { }

static inline bool nf_check_tcp_flags(const struct sk_buff *skb, int dataoff, u8 pf, u8 protonum)
{
	return false;
}

static inline bool nf_check_udp_acct(const struct nf_conn *ct, u32 extra_jiffies, bool do_acct)
{
	return false;
}

static inline int do_conntrack_confirm_ipv4(struct sk_buff *skb, const struct nf_hook_state *state)
{
	return 0;
}

static inline int  nf_ct_expect_save_init(void) { return 0; }
static inline void nf_ct_expect_save_fini(void) { }

static inline int exp_save_proc_init(struct net *net) { return 0; }
static inline void exp_save_proc_remove(struct net *net) { }

static inline void nf_ct_expect_save_insert(struct nf_conntrack_expect *exp) { }
static inline void nf_ct_expect_save_remove(struct nf_conntrack_expect *exp) { }

static inline void
nf_ct_expect_save_replace(struct nf_conntrack_expect *exp, struct nf_conntrack_expect *rep)
{
}

static inline void
nf_ct_expect_nat_report(enum ip_conntrack_expect_events event, struct nf_conntrack_expect *exp)
{
}

#endif /* CONFIG_ONT_NET_FEATURES */

#endif /* _NF_CONNTRACK_INNER_H */
